<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";
include "../resources/base64/functions.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if (!isset($_GET['date'])) {
    exit("需要传入有效的参数。");
}

$date = $_GET['date'];

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath;
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

$finished = $db->readFromFinished($date);

// -----------------------------------------------------------------------------

if ($finished == false) {
    echo <<<BBB
            <div role="alert" class="alert alert-info">
                <p class="mb-0">暂时没有相关记录。</p>
            </div>
        BBB;
} else {

    // 旧版本中，finished 表中存放的数据是 base64 编码过的，新版本中存放的是未编码过的原字符串
    if (isBase64($finished)) {
        $finished = base64_decode($finished);
    }

    $arr = json_decode($finished, true);
    if (count($arr) == 0) {
        echo <<<BBB
                <div role="alert" class="alert alert-info">
                    <p class="mb-0">暂时没有相关记录。</p>
                </div>
            BBB;
    } else {
        echo "<div class='list-group'>";
        $counter = 1;
        foreach ($arr as $item) {
            if ($counter < 10) {
                $counter = "0{$counter}";
            }
            echo <<<BBB
                <span role='button' class='list-group-item list-group-item-action btnDeleteItem text-break'>
                    <span class='text-muted small'>{$counter}. </span>
                    <span>$item</span>
                </span>
            BBB;

            $counter++;
        }
        echo "</div>";
    }
}
